package flc.ast.adapter;

import android.graphics.Color;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.riddle.lib.model.RiddleConst;
import com.stark.riddle.lib.model.RiddlePrefUtil;

import flc.ast.R;
import flc.ast.activity.SelLevelActivity;
import flc.ast.utils.Content;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.SPUtil;

public class SelLevelAdapter extends StkProviderMultiAdapter<Integer> {

    public SelLevelAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(55));
        addItemProvider(new SelLevelProvider());
    }

    private int type;

    public void setType(int type) {
        this.type = type;
    }

    private String kindName = "";//类型名称

    public void setKindName(String kindName) {
        this.kindName = kindName;
    }

    private class SelLevelProvider extends BaseItemProvider<Integer> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_level;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, Integer integer) {
            int level = 0;
            if (type == 0) {
                level = RiddlePrefUtil.getUnlockCheckPoint(RiddleConst.FuncType.RIDDLE, kindName);//获取记录的关卡位置
            } else if (type == 1) {
                level = RiddlePrefUtil.getUnlockCheckPoint(RiddleConst.FuncType.SAYING, kindName);//获取记录的关卡位置
            } else if (type == 2) {
                level = SPUtil.getInt(getContext(), Content.Idiom_Game, 1);//获取记录的关卡位置
            }else if (type == 3) {
                level = SPUtil.getInt(getContext(), Content.Tv_Game, 1);//获取记录的关卡位置
            }
            int currentLevel = integer + 1;//当前关卡数
            baseViewHolder.setText(R.id.tvSelLevelItemText, currentLevel + "");
            if (currentLevel <= level) {
                baseViewHolder.setTextColor(R.id.tvSelLevelItemText, Color.parseColor("#FFFFFF"));
                baseViewHolder.setVisible(R.id.ivSelLevelItemSel, true);
                baseViewHolder.setVisible(R.id.ivSelLevelItemNoSel, false);
            } else {
                baseViewHolder.setTextColor(R.id.tvSelLevelItemText, Color.parseColor("#8A618EC0"));
                baseViewHolder.setVisible(R.id.ivSelLevelItemSel, false);
                baseViewHolder.setVisible(R.id.ivSelLevelItemNoSel, true);
            }
        }
    }
}
